package demo1;

import java.util.Arrays;
import java.util.stream.LongStream;

/**
 * @Author liangzai
 * @Description:
 */
public class Training {
    private static final int MOD = 1_000_000_007;
    public int countTexts(String pressedKeys) {
        int n = pressedKeys.length();
        long[] f = new long[n + 1];
        f[0] = 1L;  // 什么都不按是一种方案
        char[] ch = pressedKeys.toCharArray();
        for (int i = 1; i <= n; i++) {
            f[i] = f[i - 1];  // 按一次
            for (int k = 1; k <= (ch[i - 1] == '7' || ch[i - 1] == '9' ? 3 : 2); k++) {  // 按多次
                int last = i - k;
                if (last < 1 || ch[i - 1] != ch[last - 1]) break;
                f[i] = (f[i] + f[last - 1]) % MOD;
            }
        }

        return (int) f[n];
    }

    public int countVowelPermutation(int n) {
        int mod = (int) 1e9 + 7;
        long[][] dp = new long[2][5];
        Arrays.fill(dp[0], 1);
        for (int i = 1; i < n; i++) {
            int p = i&1, q = p^1;
            dp[p][0] = (dp[q][1] + dp[q][2] + dp[q][4]) % mod;
            dp[p][1] = (dp[q][0] + dp[q][2]) % mod;
            dp[p][2] = (dp[q][1] + dp[q][3]) % mod;
            dp[p][3] = (dp[q][2]) % mod;
            dp[p][4] = (dp[q][2] + dp[q][3]) % mod;
        }
        return (int) (LongStream.of(dp[(n-1)&1]).sum() % mod);
    }


}
